From 91e94556adb352cc4ec6e7b5eaff4a9caeb1b9c1 Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Tue, 24 Nov 2020 13:42:29 -0500 Subject: [PATCH] spinbutton: Interpret localized digits Interpret input where the characters have numeric values. See #3387 --- gtk/gtkspinbutton.c | 32 +++++++++++++++++++++++++++++--- 1 file changed, 29 insertions(+), 3 deletions(-) diff --git a/gtk/gtkspinbutton.c b/gtk/gtkspinbutton.c index 88ae86ad97..a56bfb6f04 100644 --- a/gtk/gtkspinbutton.c +++ b/gtk/gtkspinbutton.c @@ -1602,9 +1602,35 @@ gtk_spin_button_default_input (GtkSpinButton *spin_button, *new_val = g_strtod (text, &err); if (*err) - return GTK_INPUT_ERROR; - else - return FALSE; + { + /* try to convert with local digits */ + gint64 val = 0; + int sign = 1; + const char *p; + + for (p = text; *p; p = g_utf8_next_char (p)) + { + gunichar ch = g_utf8_get_char (p); + + if (p == text && ch == '-') + { + sign = -1; + continue; + } + + if (!g_unichar_isdigit (ch)) + break; + + val = val * 10 + g_unichar_digit_value (ch); + } + + if (*p) + return GTK_INPUT_ERROR; + + *new_val = sign * val; + } + + return FALSE; } static void -- 2.30.2